﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data.Entity;
using Chbl.DAL;
using Chbl.DataAccess.Repositories;
using Chbl.Models;
using Chbl.ViewModels;

namespace Chbl.Controllers
{
    public class HomeController : Controller
    {
        private readonly ChblDb _db;
        private readonly IGalleryServerProRepository _galleryServerProRepository;

        public HomeController(IGalleryServerProRepository galleryServerProRepository, ChblDb chblDb)
        {
            _galleryServerProRepository = galleryServerProRepository;
             _db = chblDb;
        }

        public ActionResult Index()
        {
            int albumIdWithLatestPhotos = _db.Settings.First().AlbumIdWithLatestPhotos;
            var model = new HomeViewModel(Url, _galleryServerProRepository.GetAlbumMediaObjects(albumIdWithLatestPhotos));
            model.LoadData(_db);
            return View(model);
        }

        public ActionResult Contacts()
        {
            return View();
        }
       
        public ActionResult About()
        {
            return View();
        }

        public ActionResult Confused()
        {
            return View();
        }

        public ActionResult Trouble()
        {
            return View("Error");
        }

        [HttpPost]
        public ActionResult GetGamesResult(int tourNumber, int seasonDivisionId)
        {
            IEnumerable<Game> games =
                _db.Games.Where(g => g.TourNumber == tourNumber && g.SeasonDivisionId == seasonDivisionId)
                    .OrderBy(g => g.GameOrder).ToList();
            return PartialView("_GameResults", games);
        }
    }
}
